<?php

namespace App\Admin\Controllers;

use App\Models\BlindBox;
use App\Models\Product;
use App\Models\BlindBoxProduct;
use App\Models\BlindBoxLevel;
use App\Models\Category;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use Encore\Admin\Controllers\AdminController;

class BlindBoxProductsController extends AdminController
{
    protected $title = '盲盒商品';
    
    protected function grid()
    {
        $grid = new Grid(new BlindBoxProduct());
	
	    $grid->disableExport();
	    
	    $grid->column('blind_box_id', '盲盒')->display(function () {
	        return isset($this->blindBox) ? "{$this->blindBox->id}: {$this->blindBox->name}" : '';
        });
        $grid->column('product_id', '商品')->display(function () {
	        return isset($this->product) ? "{$this->product->id}: {$this->product->title}" : '';
        });
        $grid->column('blind_box_level_id', '等级')->display(function () {
	        return isset($this->blindBoxLevel) ? "{$this->blindBoxLevel->id}: {$this->blindBoxLevel->name}" : '';
        });
	    $grid->column('created_at', '创建时间')->display(function () {
	    	return $this->created_at->toDatetimeString();
	    });
        return $grid;
    }
    
    protected function detail($id)
    {
        $show = new Show(BlindBoxProduct::findOrFail($id));



        return $show;
    }
    
    protected function form()
    {
        $form = new Form(new BlindBoxProduct());
		$form->select('blind_box_id','盲盒名称')->options(BlindBox::all()->pluck('name', 'id'));
		$form->select('product_id','商品')->options(Product::all()->pluck('title', 'id'));
	 	$form->select('blind_box_level_id','等级')->options(BlindBoxLevel::all()->pluck('name', 'id'));

        return $form;
    }

   
}
